package com.tgy.MyFlowable.workflow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctsi.core.common.enums.StatusType;
import com.ctsi.core.common.util.$;
import com.ctsi.core.common.util.StringUtil;
import com.ctsi.core.database.entity.Search;
import com.ctsi.core.database.util.PageUtil;
import com.ctsi.workflow.dto.FlwScriptDTO;
import com.ctsi.workflow.entity.FlwScript;
import com.ctsi.workflow.mapper.FlwScriptMapper;
import com.ctsi.workflow.service.IFlwScriptService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 流程脚本表 服务实现类
 *
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2021/8/8 19:46
 */
@Service
public class FlwScriptServiceImpl extends ServiceImpl<FlwScriptMapper, FlwScript> implements IFlwScriptService {

    @Override
    public IPage<FlwScript> listPage(Search search) {
        LambdaQueryWrapper<FlwScript> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtil.isNotBlank(search.getKeyword())) {
            queryWrapper.like(FlwScript::getId, search.getKeyword());
        }
        queryWrapper.orderByDesc(FlwScript::getCreateTime);
        return this.baseMapper.selectPage(PageUtil.getPage(search), queryWrapper);
    }

    @Override
    public List<FlwScript> list(FlwScriptDTO flwScriptDTO) {
        boolean isName = $.isNoneBlank(flwScriptDTO.getName());
        return this.list(Wrappers.<FlwScript>lambdaQuery()
                .like(isName, FlwScript::getName, flwScriptDTO.getName())
                .eq(FlwScript::getStatus, StatusType.ENABLE.getCode()));
    }
}
